home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / program / asm32.zip / E32.ZIP / LOCATE.ASM < prev    next >
Assembly Source File  |  1995-01-05  |  2KB  |  106 lines

  1. ; LOCATE.ASM for E32
  2.  
  3. include    model.inc
  4.  
  5. public    locate
  6. extrn    find_start:near, find_cr:near
  7. extrn    cursor_col:near
  8.  
  9. cr    equ    13
  10.  
  11. include    dataseg.inc
  12. extrn    cursor:dword, top_of_screen:dword, cur_posn:word, save_column:byte
  13. extrn    first_row:byte, window_row:byte, display_mode:byte, filesiz:dword
  14.  
  15. locate_proc    dd _ascii
  16.         dd _hex
  17.  
  18. @curseg    ends
  19.  
  20. include    codeseg.inc
  21. ;-------------------------------------------------------------------------;
  22. ;   This subroutine positions the screen with the cursor at the row       ;
  23. ;   selected in register DH.  On entry, ESI holds the cursor offset.      ;
  24. ;-------------------------------------------------------------------------;
  25. locate    proc    near
  26.     mov    cursor,esi
  27.     sub    dh,first_row
  28.     movzx    eax,display_mode
  29.     jmp    locate_proc[eax]
  30.  
  31. _hex:
  32. ; limit offset to file size
  33.     mov    eax,filesiz
  34.     dec    eax
  35.     cmp    esi,eax
  36.     jb    short _hex0
  37.     mov    esi,eax
  38. _hex0:
  39.     mov    cursor,esi
  40.     mov    eax,esi
  41.     and    esi,0ffffFFF0h
  42.     sub    eax,esi
  43.     mov    dl,al        ; column offset
  44.     shl    al,1
  45.     add    dl,al
  46.     add    dl,10        ; cursor pos
  47.     mov    al,dh        ; save row offset
  48.     add    dh,first_row
  49.  
  50.     mov    bl,10h
  51.     mul    bl
  52.     movzx    eax,ax
  53.     sub    esi,eax
  54.     jnc    short _hex9
  55.     neg    esi
  56.     mov    eax,esi
  57.     div    bl
  58.     sub    dh,al
  59.     xor    esi,esi
  60. _hex9:
  61.     mov    cur_posn,dx
  62.     mov    top_of_screen,esi
  63.     ret
  64.  
  65. _ascii:
  66.     push    es
  67.     movzx    ecx,dh
  68.     xor    edx,edx        ; start at the top of the window
  69.     test    esi,esi        ; at start of buffer?
  70.     jz    short locate_first
  71.     call    find_start    ; get start of this row
  72.     test    esi,esi        ; is cursor at start of file?
  73.     jz    short locate_first
  74.     jecxz    locate_first    ; if locating to top row, we're done
  75.     push    fs
  76.     pop    es
  77. find_top:
  78.     push    esi
  79.     push    ecx
  80.     call    find_CR
  81.     pop    ecx
  82.     pop    eax
  83.     cmp    byte ptr es:[esi],CR
  84.     jne    short locate_first
  85.     cmp    esi,eax
  86.     je    short locate_done
  87.     inc    dh
  88.     loop    find_top
  89. locate_done:
  90.     push    cursor
  91.     mov    cursor,esi
  92.     call    find_start
  93.     pop    cursor
  94. locate_first:
  95.     mov    top_of_screen,esi
  96.     add    dh,first_row
  97.     mov    cur_posn,dx
  98.     call    cursor_col
  99.     mov    save_column,dl
  100.     pop    es
  101.     ret
  102. locate    endp
  103.  
  104. @curseg    ends
  105.     end
  106.